package com.googlecode.designrules;

import java.util.HashSet;
import java.util.Set;

import org.designwizard.design.PackageNode;
import org.designwizard.main.DesignWizard;

public class PackageAssert extends DesignAssert {

	private final String packageName;

	public PackageAssert(DesignWizard dw, String packageName) {
		super(dw);
		this.packageName = packageName;
	}

	public final void doesNotUsePackage(String otherPackage) {
		PackageNode thisPackage = getPackage(packageName);
		PackageNode thatPackage = getPackage(otherPackage);
		if (thatPackage.getCallersPackages().contains(thisPackage)) {
			fail("The package " + packageName + " is using the package " + otherPackage);
		}
	}

	public final void doesNotUseAnyOfThesePackages(String... packages) {
		PackageNode thisPackage = getPackage(packageName);
		Set<String> callingPackages = new HashSet<String>();
		for (String otherPackage : packages) {
			PackageNode thatPackage = getPackage(otherPackage);
			if (thatPackage.getCallersPackages().contains(thisPackage)) {
				callingPackages.add(otherPackage);
			}
		}

		if (callingPackages.size() > 0) {
			fail("The package " + packageName + " is using the package(s) " + callingPackages);
		}
	}

}
